package com.lovely3x.loginandresgiter.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.litesuits.orm.db.annotation.Column;
import com.litesuits.orm.db.annotation.Mapping;
import com.litesuits.orm.db.annotation.PrimaryKey;
import com.litesuits.orm.db.annotation.Table;
import com.litesuits.orm.db.enums.AssignType;
import com.litesuits.orm.db.enums.Relation;
import com.lovely3x.common.managements.user.IUser;
import com.lovely3x.common.managements.user.IUserPreferences;
import com.lovely3x.common.utils.PoJoCopier;

/**
 * user的简易实现
 * Created by lovely3x on 16-4-15.
 */
@Table(SimpleUser.TABLE_NAME)
public class SimpleUser implements IUser, Parcelable {

    /**
     * 表名
     */
    public static final String TABLE_NAME = "tab_user";

    @Column("user_state")
    private int mUserState = STATE_OFFLINE;

    @Column("token")
    private String token;

    /**
     * 电话号码
     */
    @Column("phone")
    @PrimaryKey(AssignType.BY_MYSELF)
    private long phone;
    /**
     * 密码
     */
    private String password;

    /**
     * MD5 密码
     */
    @Column("md5_password")
    private String MD5Password;

    /**
     * 生日
     */
    @Column("birthday")
    private long birthday;
    /**
     * 性别
     */
    @Column("sex")
    private int sex;
    /**
     * 昵称
     */
    @Column("nickname")
    private String nickname;
    /**
     * 头像地址
     */
    @Column("headaddress")
    private String headaddress;
    /**
     * 年龄
     */
    @Column("age")
    private int age;
    /**
     * 环信的用户名
     */
    @Column("easemob_user_name")
    private String easemobUsername;

    /**
     * 签名
     */
    @Column("user_information")
    private String userInformation;

    /**
     * 邀请码
     */
    @Column("invite_code")
    private String inviteCode;

    /**
     * 用户名
     */
    @Column("user_name")
    private String userName;

    /**
     * 用户偏好设置
     */
    @Mapping(Relation.OneToOne)
    private SimpleUserPreferences preference = new SimpleUserPreferences();
    /**
     * 体重
     */
    @Column("_weight")
    private float weight;
    /**
     * 身高
     */
    @Column("_height")
    private float height;

    /**
     * 用户id
     */
    @Column("_uid")
    private String uid;

    @Column("_last_login_time")
    private long lastLoginTime;

    /**
     * 用户的类型
     */
    @PoJoCopier.Ignore
    @Column("_type")
    private int type = -1;

    @Column("_profession")
    private String profession;

    @Column("_divisionname")
    private String divisionname;

    @Column("_jobtitle")
    private String jobtitle;

    @Column("_sparemoney")
    private float sparemoney;

    @Column("_usergrade")
    private float usergrade;

    @Column("_name")
    private String name;

    @Column("_isvip")
    private boolean isvip;

    //（-1：未认证  0：认证中   1：成功   2：失败）
    @Column("_isauth")
    private int isauth;

    @Column("_hospital")
    private String hospital;

    @Column("_ispaypwd")
    private boolean ispaypwd;

    /**
     * 是否绑定手机
     */
    @Column("_isphone")
    private boolean isphone;

    /**
     * 用户账号
     */
    @Column("_userPhone")
    private String userPhone;//用户账号

    /**
     * 银行卡账号
     */
    @Column("_bankCard")
    private String bankCard;//银行卡账号

    /**
     * 身份证号
     */
    @Column("_idCard")
    private String idCard;//身份证号

    /**
     * 支付密码
     */
    @Column("_payPwd")
    private String payPwd;//支付密码


    public SimpleUser(String userPhone, String bankCard, String idCard, String payPwd) {
        this.userPhone = userPhone;
        this.bankCard = bankCard;
        this.idCard = idCard;
        this.payPwd = payPwd;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getBankCard() {
        return bankCard;
    }

    public void setBankCard(String bankCard) {
        this.bankCard = bankCard;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getPayPwd() {
        return payPwd;
    }

    public void setPayPwd(String payPwd) {
        this.payPwd = payPwd;
    }

    @Override
    public String toString() {
        return "SimpleUser{" +
                "userPhone='" + userPhone + '\'' +
                ", bankCard='" + bankCard + '\'' +
                ", idCard='" + idCard + '\'' +
                ", payPwd='" + payPwd + '\'' +
                '}';
    }

    public SimpleUser(boolean ispaypwd) {
        this.ispaypwd = ispaypwd;
    }

    public static String getTableName() {
        return TABLE_NAME;
    }

    public boolean ispaypwd() {
        return ispaypwd;
    }

    public void setIspaypwd(boolean ispaypwd) {
        this.ispaypwd = ispaypwd;
    }

    public static Creator<SimpleUser> getCREATOR() {
        return CREATOR;
    }


    @Override
    public void setState(int state) {
        mUserState = state;
    }

    @Override
    public int getState() {
        return mUserState;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public String getDivisionname() {
        return divisionname;
    }

    public void setDivisionname(String divisionname) {
        this.divisionname = divisionname;
    }

    public String getJobtitle() {
        return jobtitle;
    }

    public void setJobtitle(String jobtitle) {
        this.jobtitle = jobtitle;
    }

    public float getSparemoney() {
        return sparemoney;
    }

    public void setSparemoney(float sparemoney) {
        this.sparemoney = sparemoney;
    }

    public float getUsergrade() {
        return usergrade;
    }

    public void setUsergrade(float usergrade) {
        this.usergrade = usergrade;
    }

    public void setUsergrade(int usergrade) {
        this.usergrade = usergrade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isvip() {
        return isvip;
    }

    public void setIsvip(boolean isvip) {
        this.isvip = isvip;
    }

    public int getIsauth() {
        return isauth;
    }

    public void setIsauth(int isauth) {
        this.isauth = isauth;
    }

    public String getHospital() {
        return hospital;
    }

    public void setHospital(String hospital) {
        this.hospital = hospital;
    }


    @Override
    public IUser clone() {
        try {
            return (IUser) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }


    public SimpleUser() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SimpleUser that = (SimpleUser) o;

        if (mUserState != that.mUserState) return false;
        if (phone != that.phone) return false;
        if (birthday != that.birthday) return false;
        if (sex != that.sex) return false;
        if (age != that.age) return false;
        if (Float.compare(that.weight, weight) != 0) return false;
        if (Float.compare(that.height, height) != 0) return false;
        if (lastLoginTime != that.lastLoginTime) return false;
        if (type != that.type) return false;
        if (Float.compare(that.sparemoney, sparemoney) != 0) return false;
        if (Float.compare(that.usergrade, usergrade) != 0) return false;
        if (isvip != that.isvip) return false;
        if (isauth != that.isauth) return false;
        if (ispaypwd != that.ispaypwd) return false;
        if (token != null ? !token.equals(that.token) : that.token != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null)
            return false;
        if (MD5Password != null ? !MD5Password.equals(that.MD5Password) : that.MD5Password != null)
            return false;
        if (nickname != null ? !nickname.equals(that.nickname) : that.nickname != null)
            return false;
        if (headaddress != null ? !headaddress.equals(that.headaddress) : that.headaddress != null)
            return false;
        if (easemobUsername != null ? !easemobUsername.equals(that.easemobUsername) : that.easemobUsername != null)
            return false;
        if (userInformation != null ? !userInformation.equals(that.userInformation) : that.userInformation != null)
            return false;
        if (inviteCode != null ? !inviteCode.equals(that.inviteCode) : that.inviteCode != null)
            return false;
        if (userName != null ? !userName.equals(that.userName) : that.userName != null)
            return false;
        if (preference != null ? !preference.equals(that.preference) : that.preference != null)
            return false;
        if (uid != null ? !uid.equals(that.uid) : that.uid != null) return false;
        if (profession != null ? !profession.equals(that.profession) : that.profession != null)
            return false;
        if (divisionname != null ? !divisionname.equals(that.divisionname) : that.divisionname != null)
            return false;
        if (jobtitle != null ? !jobtitle.equals(that.jobtitle) : that.jobtitle != null)
            return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        return hospital != null ? hospital.equals(that.hospital) : that.hospital == null;

    }

    public boolean isphone() {
        return isphone;
    }

    public void setIsphone(boolean isphone) {
        this.isphone = isphone;
    }

    @Override
    public int hashCode() {
        int result = mUserState;
        result = 31 * result + (token != null ? token.hashCode() : 0);
        result = 31 * result + (int) (phone ^ (phone >>> 32));
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (MD5Password != null ? MD5Password.hashCode() : 0);
        result = 31 * result + (int) (birthday ^ (birthday >>> 32));
        result = 31 * result + sex;
        result = 31 * result + (nickname != null ? nickname.hashCode() : 0);
        result = 31 * result + (headaddress != null ? headaddress.hashCode() : 0);
        result = 31 * result + age;
        result = 31 * result + (easemobUsername != null ? easemobUsername.hashCode() : 0);
        result = 31 * result + (userInformation != null ? userInformation.hashCode() : 0);
        result = 31 * result + (inviteCode != null ? inviteCode.hashCode() : 0);
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (preference != null ? preference.hashCode() : 0);
        result = 31 * result + (weight != +0.0f ? Float.floatToIntBits(weight) : 0);
        result = 31 * result + (height != +0.0f ? Float.floatToIntBits(height) : 0);
        result = 31 * result + (uid != null ? uid.hashCode() : 0);
        result = 31 * result + (int) (lastLoginTime ^ (lastLoginTime >>> 32));
        result = 31 * result + type;
        result = 31 * result + (profession != null ? profession.hashCode() : 0);
        result = 31 * result + (divisionname != null ? divisionname.hashCode() : 0);
        result = 31 * result + (jobtitle != null ? jobtitle.hashCode() : 0);
        result = 31 * result + (sparemoney != +0.0f ? Float.floatToIntBits(sparemoney) : 0);
        result = 31 * result + (usergrade != +0.0f ? Float.floatToIntBits(usergrade) : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (isvip ? 1 : 0);
        result = 31 * result + isauth;
        result = 31 * result + (hospital != null ? hospital.hashCode() : 0);
        result = 31 * result + (ispaypwd ? 1 : 0);
        return result;
    }


    public int getmUserState() {
        return mUserState;
    }

    public void setmUserState(int mUserState) {
        this.mUserState = mUserState;
    }

    public String getMD5Password() {
        return MD5Password;
    }

    public void setMD5Password(String MD5Password) {
        this.MD5Password = MD5Password;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public long getPhone() {
        return phone;
    }

    public void setPhone(long phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public long getBirthday() {
        return birthday;
    }

    public void setBirthday(long birthday) {
        this.birthday = birthday;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public IUserPreferences getPreference() {
        return preference;
    }

    public void setPreference(SimpleUserPreferences preference) {
        this.preference = preference;
    }

    public float getWeight() {
        return weight;
    }

    public void setWeight(float weight) {
        this.weight = weight;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public long getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(long lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getHeadaddress() {
        return headaddress;
    }

    public void setHeadaddress(String headaddress) {
        this.headaddress = headaddress;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getEasemobUsername() {
        return easemobUsername;
    }

    public void setEasemobUsername(String easemobUsername) {
        this.easemobUsername = easemobUsername;
    }

    public String getUserInformation() {
        return userInformation;
    }

    public void setUserInformation(String userInformation) {
        this.userInformation = userInformation;
    }

    public String getInviteCode() {
        return inviteCode;
    }

    public void setInviteCode(String inviteCode) {
        this.inviteCode = inviteCode;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.mUserState);
        dest.writeString(this.token);
        dest.writeLong(this.phone);
        dest.writeString(this.password);
        dest.writeString(this.MD5Password);
        dest.writeLong(this.birthday);
        dest.writeInt(this.sex);
        dest.writeString(this.nickname);
        dest.writeString(this.headaddress);
        dest.writeInt(this.age);
        dest.writeString(this.easemobUsername);
        dest.writeString(this.userInformation);
        dest.writeString(this.inviteCode);
        dest.writeString(this.userName);
        dest.writeParcelable(this.preference, flags);
        dest.writeFloat(this.weight);
        dest.writeFloat(this.height);
        dest.writeString(this.uid);
        dest.writeLong(this.lastLoginTime);
        dest.writeInt(this.type);
        dest.writeString(this.profession);
        dest.writeString(this.divisionname);
        dest.writeString(this.jobtitle);
        dest.writeFloat(this.sparemoney);
        dest.writeFloat(this.usergrade);
        dest.writeString(this.name);
        dest.writeByte(this.isvip ? (byte) 1 : (byte) 0);
        dest.writeInt(this.isauth);
        dest.writeString(this.hospital);
        dest.writeByte(this.ispaypwd ? (byte) 1 : (byte) 0);
        dest.writeByte(this.isphone ? (byte) 1 : (byte) 0);
        dest.writeString(this.userPhone);
        dest.writeString(this.bankCard);
        dest.writeString(this.idCard);
        dest.writeString(this.payPwd);
    }

    protected SimpleUser(Parcel in) {
        this.mUserState = in.readInt();
        this.token = in.readString();
        this.phone = in.readLong();
        this.password = in.readString();
        this.MD5Password = in.readString();
        this.birthday = in.readLong();
        this.sex = in.readInt();
        this.nickname = in.readString();
        this.headaddress = in.readString();
        this.age = in.readInt();
        this.easemobUsername = in.readString();
        this.userInformation = in.readString();
        this.inviteCode = in.readString();
        this.userName = in.readString();
        this.preference = in.readParcelable(SimpleUserPreferences.class.getClassLoader());
        this.weight = in.readFloat();
        this.height = in.readFloat();
        this.uid = in.readString();
        this.lastLoginTime = in.readLong();
        this.type = in.readInt();
        this.profession = in.readString();
        this.divisionname = in.readString();
        this.jobtitle = in.readString();
        this.sparemoney = in.readFloat();
        this.usergrade = in.readFloat();
        this.name = in.readString();
        this.isvip = in.readByte() != 0;
        this.isauth = in.readInt();
        this.hospital = in.readString();
        this.ispaypwd = in.readByte() != 0;
        this.isphone = in.readByte() != 0;
        this.userPhone = in.readString();
        this.bankCard = in.readString();
        this.idCard = in.readString();
        this.payPwd = in.readString();
    }

    public static final Creator<SimpleUser> CREATOR = new Creator<SimpleUser>() {
        @Override
        public SimpleUser createFromParcel(Parcel source) {
            return new SimpleUser(source);
        }

        @Override
        public SimpleUser[] newArray(int size) {
            return new SimpleUser[size];
        }
    };
}
